// DBFViewDoc.cpp : implementation of the CDBFViewDoc class
//

#include "stdafx.h"
#include "DBFViewApp.h"

#include "DBFViewDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDBFViewDoc

IMPLEMENT_DYNCREATE(CDBFViewDoc, CDocument)

BEGIN_MESSAGE_MAP(CDBFViewDoc, CDocument)
	//{{AFX_MSG_MAP(CDBFViewDoc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDBFViewDoc construction/destruction

CDBFViewDoc::CDBFViewDoc()
{
}

CDBFViewDoc::~CDBFViewDoc()
{
	if(m_Set.IsOpen())
		m_Set.Close();
}

BOOL CDBFViewDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDBFViewDoc serialization

void CDBFViewDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDBFViewDoc diagnostics

#ifdef _DEBUG
void CDBFViewDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDBFViewDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDBFViewDoc commands

BOOL CDBFViewDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	DeleteContents();
	SetModifiedFlag(FALSE);

	BOOL bResult = TRUE;
	if(m_Set.IsOpen())
		m_Set.Close();

try
{
	m_Set.Open(lpszPathName);
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}
	if(!m_Set.IsOpen())
		bResult = FALSE;

	return bResult;
}










